home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / WUNZ20SR.ZIP / KBDPROC.C < prev    next >
C/C++ Source or Header  |  1992-07-02  |  2KB  |  63 lines

  1. #include "wizunzip.h"
  2.  
  3. /* Keyboard procedure used to sub-class all windows which can be
  4.  * tab stops.
  5.  */
  6.  
  7. /* Keyboard procedure
  8.  * This function allows the user to tab and back-tab among the 
  9.  * listbox, four command buttons,and message window.  
  10.  * It traps VK_TAB messages and sets the
  11.  * focus on the next or previous window as required.
  12.  * Skip any disabled buttons.
  13.  */
  14. long FAR PASCAL KbdProc(HWND hWnd, WORD wMessage, WORD wParam, LONG lParam)
  15. {
  16.     int nID = GetWindowWord(hWnd, GWW_ID); /* child window ID no. */
  17.     int nTabStopTableIndex = nID - TABSTOP_ID_BASE;
  18.     int nNextTabStopTableIndex = nTabStopTableIndex;
  19.  
  20.     if (wMessage == WM_KEYDOWN)
  21.     {
  22.         if (wParam == VK_TAB)
  23.         {
  24.             int nRelIndex = /* forward or backward ? */
  25.                     (int)(GetKeyState(VK_SHIFT) < 0 ? -1 : 1);
  26.  
  27.             do {
  28.                 nNextTabStopTableIndex += nRelIndex;
  29.                 if (nNextTabStopTableIndex < 0)
  30.                     nNextTabStopTableIndex = TABSTOP_TABLE_ENTRIES-1;
  31.                 else if (nNextTabStopTableIndex >= TABSTOP_TABLE_ENTRIES)
  32.                     nNextTabStopTableIndex = 0;
  33.             
  34.             } while (!IsWindowEnabled(TabStopTable[nNextTabStopTableIndex].hWnd));
  35.  
  36.             SetFocus(TabStopTable[nNextTabStopTableIndex].hWnd);
  37.         }
  38.         else if (wParam == VK_F1)
  39.         {
  40.            /* If Shift-F1, turn help mode on and set help cursor */ 
  41.            if (GetKeyState(VK_SHIFT)<0)
  42.            {
  43.                uf.fHelp = TRUE;
  44.                SetCursor(hHelpCursor);
  45.            }
  46.            else
  47.            {
  48.                /* If F1 without shift, then call up help main index topic */ 
  49.                WinHelp(hWndMain, szHelpFileName, HELP_INDEX, 0L);
  50.            }
  51.         }
  52.         else if ((wParam == VK_ESCAPE) && uf.fHelp)
  53.         {
  54.                /* Escape during help mode: turn help mode off */
  55.                uf.fHelp = FALSE;
  56.                SetCursor((HCURSOR)GetClassWord(hWndMain,GCW_HCURSOR));
  57.         }
  58.     }
  59.  
  60.     return CallWindowProc(TabStopTable[nTabStopTableIndex].lpfnOldFunc,
  61.                             hWnd, wMessage, wParam, lParam);
  62. }            
  63.